home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / gamesmaster / demosrc / stars8.s < prev    next >
Text File  |  1996-07-16  |  9KB  |  328 lines

  1. ;3D STARFIELD 8
  2. ;--------------
  3. ;Same as the first starfield demo but runs in 8 colours.  Default is 600
  4. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  5. ;real visual experience :-)
  6.  
  7.     opt    o+
  8.  
  9.     INCLUDE    "exec/exec_lib.i"
  10.     INCLUDE    "games/games_lib.i"
  11.     INCLUDE    "games/games.i
  12.     INCLUDE    "games/gamesbase.i"
  13.  
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17.  
  18. NSTARS    =    600                      ;Number of stars
  19.  
  20. XSPEED    =    -4
  21. YSPEED    =    6
  22. ZSPEED    =    2
  23.  
  24. SCR_HEIGHT =    256
  25. SCR_WIDTH =    320
  26.  
  27.     SECTION    "Stars",CODE
  28.  
  29. ;==========================================================================;
  30. ;                             INITIALISE DEMO
  31. ;==========================================================================;
  32.  
  33. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  34.     move.l    ($4).w,a6
  35.     lea    GMS_Name(pc),a1
  36.     moveq    #$00,d0
  37.     CALL    OpenLibrary
  38.     move.l    d0,GMS_Base
  39.     beq    Quit
  40.  
  41.     move.l    GMS_Base(pc),a6
  42.     CALL    SetUserPri
  43.  
  44.     move.l    GMS_Base(pc),a6          ;Tell GMS that we want to add a
  45.     lea    ScreenStruct(pc),a0      ;screen for use.
  46.     CALL    Add_Screen
  47.     tst.l    d0
  48.     bne    Error
  49.  
  50.     lea    ScreenStruct(pc),a0      ;Now show the screen/pic.
  51.     CALL    Show_Screen
  52.  
  53. ;==========================================================================;
  54.  
  55. ;==========================================================================;
  56.  
  57.     ;Randomize star coordinates
  58.  
  59.     lea    StarCoords,a0            ;a0 = Ptr to star co-ordinates.
  60.     move.w    #NSTARS-1,d7
  61. .loop1    move.w    #8192,d1
  62.     CALL    SlowRandom
  63.     move.w    d0,(a0)+
  64.     CALL    SlowRandom
  65.     move.w    d0,(a0)+
  66.     CALL    SlowRandom
  67.     move.w    d0,(a0)+
  68.     dbra    d7,.loop1
  69.  
  70.     ;Construct perspective table
  71.  
  72.     lea    PersTable,a0             ;a0 = ptr to perspective table.
  73.     moveq    #0,d1                    ;d1 = Starting at 0.
  74. .loop2    move.l    #$95FFFF,d2              ;d2 = $95FFFF
  75.     move.l    d1,d3                    ;d3 = d1
  76.     add.w    #300,d3                  ;d3 = ++300
  77.     divu    d3,d2                    ;d2 = ($95ffff)/d3
  78.     move.w    d2,(a0)+                 ;a0 = d2+
  79.     addq.w    #1,d1                    ;d1 = ++1
  80.     cmp.w    #8192,d1                 ;d1 = Equal to 8192?
  81.     bne.s    .loop2
  82.  
  83.     ;Construct plot tables for fast drawing.
  84.  
  85.     lea    PlotXTable,a0            ;a0 = X table - byte positions.
  86.     lea    PlotBTable,a1            ;a1 = Bit table (X related).
  87.     lea    PlotYTable,a2            ;a2 = Y table - line position.
  88.     moveq    #0,d0                    ;d0 = 00
  89. .loop3    move.w    d0,d1                    ;d1 = d0
  90.     lsr.w    #3,d1                    ;d1 = (d0)<<3
  91.     move.w    d1,(a0)+                 ;a0 = d1+
  92.  
  93.     move.w    d0,d1                    ;d1 = d0
  94.     eor.w    #$FFFF,d1                ;d1 = (d0) eor $ffff
  95.     and.w    #%00000111,d1            ;d1 = &%00000111
  96.     move.w    d1,(a1)+                 ;a1 = BitSet++
  97.  
  98.     cmp.w    #SCR_HEIGHT,d0           ;Write out the Y values for the
  99.     bge.s    .plot2                   ;table.
  100.     move.w    d0,d1                    ;d1 = Line Number.
  101.     mulu    #120,d1                  ;d1 = (LineNumber)*80
  102.     move.w    d1,(a2)+                 ;a2 = (LineNumber*80)++
  103.  
  104. .plot2    addq.w    #1,d0
  105.     cmp.w    #SCR_WIDTH,d0
  106.     bne.s    .loop3
  107.  
  108. ;==========================================================================;
  109. ;                                MAIN LOOP
  110. ;==========================================================================;
  111.  
  112. MainLoop:
  113.     move.l    GMS_Base(pc),a6
  114.     CALL    Wait_OSVBL
  115.  
  116.     lea    ScreenStruct(pc),a0
  117.     CALL    SwapBuffers
  118.  
  119. ;==========================================================================;
  120. ;                             STAR ANIMATION
  121. ;==========================================================================;
  122.  
  123.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  124.     add.w    #XSPEED,d0               ;d0 = (StarXPos)+XSPEED
  125.     add.w    #YSPEED,d1               ;d1 = (StarYPos)+YSPEED
  126.     add.w    #ZSPEED,d2               ;d2 = (StarZPos)+ZSPEED
  127.     and.w    #%0000011111111111,d0
  128.     and.w    #%0000011111111111,d1
  129.     and.w    #%0000011111111111,d2
  130.     movem.w    d0/d1/d2,StarXPos
  131.  
  132.     lea    Sinus(pc),a0             ;a0 = Sinus table.
  133.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  134.     add.w    (a0,d0.w),d3
  135.     add.w    (a0,d1.w),d4
  136.     add.w    (a0,d2.w),d5
  137.     movem.w    d3/d4/d5,StarXAdd
  138.  
  139. ;===========================================================================;
  140. ;                              SCREEN CLEAR
  141. ;===========================================================================;
  142. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  143.  
  144. .wait    btst    #6,$dff002
  145.     bne.s    .wait
  146.     move.l    ScreenStruct+SS_MemPtr3(pc),$dff054
  147.     move.w    #0,$dff066
  148.     move.l    #$01000000,$dff040
  149.     move.w    #(SCR_HEIGHT*AMT_PLANES<<6)+SCR_WIDTH/16,$dff058
  150.  
  151. ;==========================================================================;
  152. ;                               DRAW STARS
  153. ;==========================================================================;
  154.  
  155.     lea    StarCoords,a0            ;Draw starfield
  156.     lea    PersTable,a1             ;a1 = Perspective table.
  157.     lea    PlotXTable,a2            ;a2 = X table.
  158.     lea    PlotBTable,a3            ;a3 = Bit table.
  159.     lea    PlotYTable,a4            ;a4 = Y table.
  160.  
  161.     move.l    ScreenStruct+SS_MemPtr2(pc),a6
  162.  
  163.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  164.     add.w    #4096,d3                 ;d3 = ++4096
  165.     add.w    #4096,d4                 ;d4 = ++4096
  166.  
  167.     move.w    #NSTARS-1,d7
  168.  
  169. .draw    movem.w    (a0)+,d0/d1/d2           ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  170.     add.w    d3,d0                    ;Increase XPos.
  171.     and.w    #8191,d0                 ;d0 = And'd
  172.     sub.w    #4096,d0                 ;d0 = --4096
  173.  
  174.     add.w    d4,d1                    ;Y-movement
  175.     and.w    #8191,d1                 ;d1 = And'd
  176.     sub.w    #4096,d1                 ;d1 = --4096
  177.  
  178.     add.w    d5,d2                    ;Z-movement
  179.     and.w    #8191,d2
  180.     add.w    d2,d2                    ;d2 = *2 [word]
  181.     move.w    (a1,d2.w),d6             ;d6 = Read from Perspective table.
  182.  
  183.     muls    d6,d0                    ;X-projection
  184.     swap    d0
  185.     add.w    #176,d0
  186.  
  187.     cmp.w    #SCR_WIDTH-1,d0
  188.     bhi    .nodraw
  189.     muls    d6,d1                    ;Y-projection
  190.     swap    d1
  191.     add.w    #136,d1
  192.     cmp.w    #SCR_HEIGHT-1,d1
  193.     bhi    .nodraw
  194.  
  195.     add.w    d0,d0                    ;d0 = *2 [word]
  196.     add.w    d1,d1                    ;d1 = *2 [word]
  197.     move.w    (a4,d1.w),d6             ;d6 = Plot Y.
  198.     add.w    (a2,d0.w),d6             ;d6 = ++PlotX.
  199.     move.w    (a3,d0.w),d0             ;d0 = BitValue.
  200.  
  201. .draw1    cmp.w    #4000,d2                 ;Now draw the star according to
  202.     bgt.s    .draw2                   ;its position in the Z axis.
  203.     bset    d0,(a6,d6.w)
  204.     dbra    d7,.draw
  205.     bra.s    .done
  206.  
  207. .draw2    cmp.w    #6000,d2
  208.     bgt.s    .draw3
  209.     bset    d0,40(a6,d6.w)
  210.     dbra    d7,.draw
  211.     bra.s    .done
  212.  
  213. .draw3    cmp.w    #8000,d2
  214.     bgt.s    .draw4
  215.     bset    d0,(a6,d6.w)
  216.     bset    d0,40(a6,d6.w)
  217.     dbra    d7,.draw
  218.     bra.s    .done
  219.  
  220. .draw4    cmp.w    #10000,d2
  221.     bgt.s    .draw5
  222.     bset    d0,80(a6,d6.w)
  223.     dbra    d7,.draw
  224.     bra.s    .done
  225.  
  226. .draw5    cmp.w    #12000,d2
  227.     bgt.s    .draw6
  228.     bset    d0,(a6,d6.w)
  229.     bset    d0,80(a6,d6.w)
  230.     dbra    d7,.draw
  231.     bra.s    .done
  232.  
  233. .draw6    cmp.w    #14000,d2
  234.     bgt.s    .draw7
  235.     bset    d0,40(a6,d6.w)
  236.     bset    d0,80(a6,d6.w)
  237.     dbra    d7,.draw
  238.     bra.s    .done
  239.  
  240. .draw7    bset    d0,(a6,d6.w)
  241.     bset    d0,40(a6,d6.w)
  242.     bset    d0,80(a6,d6.w)
  243. .nodraw    dbra    d7,.draw
  244.  
  245. .done    move.l    GMS_Base(pc),a6
  246.     moveq    #JPORT1,d0               ;Read from port 1 (mouse).
  247.     moveq    #JT_SWITCH,d1
  248.     CALL    Read_JoyPort             ;Go get joystick status.
  249.     btst    #JS_FIRE1,d0
  250.     beq    MainLoop
  251.  
  252. ;===========================================================================;
  253. ;                              RETURN TO DOS
  254. ;===========================================================================;
  255.  
  256.     move.l    GMS_Base(pc),a6
  257.     lea    ScreenStruct(pc),a0
  258.     CALL    Delete_Screen            ;Give back screen memory etc.
  259. Error    move.l    GMS_Base(pc),a1
  260.     move.l    ($4).w,a6
  261.     CALL    CloseLibrary
  262. Quit    MOVEM.L    (SP)+,A0-A6/D1-D7
  263.     moveq    #$00,d0
  264.     rts
  265.  
  266. ;===========================================================================;
  267. ;                                  DATA
  268. ;===========================================================================;
  269.  
  270. GMS_Name:
  271.     dc.b    "games.library",0
  272.     even
  273. GMS_Base:
  274.     dc.l    0
  275.  
  276. AMT_PLANES =    3
  277.  
  278. ScreenStruct:
  279.     dc.l    "GSV1"
  280.     dc.l    0,0,0                    ;Screen_Mem1/2/3
  281.     dc.l    0                        ;Screen link.
  282.     dc.l    ScreenPalette            ;Address of screen palette.
  283.     dc.l    0                        ;Address of rasterlist.
  284.     dc.l    0                        ;Amt of colours in palette.
  285.     dc.w    256,320,320/8            ;Screen Height, Width, Width/8
  286.     dc.w    256,320,320/8            ;Pic Height, Width, Width/8
  287.     dc.w    AMT_PLANES               ;Amt_Planes
  288.     dc.w    0,0                      ;Top Of Screen, X/Y
  289.     dc.w    0                        ;Scroll buffer in pixels/8.
  290.     dc.w    0,0                      ;X/Y counters (for scrolling).
  291.     dc.l    TPLBUFFER|NOBURST        ;Special attributes.
  292.     dc.w    LORES                    ;Screen mode.
  293.     dc.b    INTERLEAVED              ;Screen type
  294.     dc.b    0                        ;Screen Is Being Displayed?
  295.     dc.l    0,0                      ;Reserved area.
  296.     even
  297.  
  298. ScreenPalette:                           ; 124   124   124   124
  299.     dc.w    $0000,$0eee,$0ccc,$0aaa  ;%000, %100, %010, %110
  300.     dc.w    $0888,$0666,$0333,$0222  ;%001, %101, %011, %111
  301.  
  302. ;===========================================================================;
  303. ;                                STAR DATA
  304. ;===========================================================================;
  305.  
  306. StarXAdd dc.w    33                       ;Star stuff
  307. StarYAdd dc.w    12
  308. StarZAdd dc.w    -114
  309.  
  310. StarXPos dc.w    0                        ;Sinus positions
  311. StarYPos dc.w    310
  312. StarZPos dc.w    1280
  313.  
  314.     INCLUDE    "StarSinus.i"
  315.  
  316.     SECTION    Storage,BSS
  317.  
  318. StarCoords
  319.     ds.w    NSTARS*3                 ;Star coordinates
  320.  
  321. PersTable
  322.     ds.w    8192                     ;Perspective table
  323.  
  324. PlotXTable ds.w    SCR_WIDTH                ;Plot tables
  325. PlotBTable ds.w    SCR_WIDTH
  326. PlotYTable ds.w    SCR_HEIGHT
  327.  
  328.